package com.base.commons.elasticsearch.override;

import org.frameworkset.elasticsearch.client.ClientInterface;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author carl
 */
public class EsMapperProxy<T> implements InvocationHandler {
    private Class<T> esMapperInterface;
    private ClientInterface clientInterface;

    public EsMapperProxy(Class<T> esMapperInterface,ClientInterface clientInterface) {
        this.esMapperInterface = esMapperInterface;
        this.clientInterface = clientInterface;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (Object.class.equals(method.getDeclaringClass())) {
            return method.invoke(this,args);
        }
        return method.invoke(clientInterface, args);
    }
}
